﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Aug.iot.Configuration;
using Aug.iot.Web;

namespace Aug.iot.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class iotDbContextFactory : IDesignTimeDbContextFactory<iotDbContext>
    {
        public iotDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<iotDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            iotDbContextConfigurer.Configure(builder, configuration.GetConnectionString(iotConsts.ConnectionStringName));

            return new iotDbContext(builder.Options);
        }
    }
}
